﻿IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
    CREATE TABLE [__EFMigrationsHistory] (
        [MigrationId] nvarchar(150) NOT NULL,
        [ProductVersion] nvarchar(32) NOT NULL,
        CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
    );
END;

GO

CREATE TABLE [ActionEntity] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] nvarchar(max) NULL,
    [ActionType] int NOT NULL,
    [AssignTo] nvarchar(max) NULL,
    CONSTRAINT [PK_ActionEntity] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [Ambulance] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] nvarchar(max) NULL,
    [ResourceKey] nvarchar(max) NULL,
    CONSTRAINT [PK_Ambulance] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [Appliance] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] uniqueidentifier NOT NULL,
    [ResourceKey] nvarchar(max) NULL,
    CONSTRAINT [PK_Appliance] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [IncCurrentRes] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] nvarchar(max) NULL,
    [ResourceKey] nvarchar(max) NULL,
    CONSTRAINT [PK_IncCurrentRes] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [Incident] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] uniqueidentifier NOT NULL,
    [GroupId] nvarchar(max) NULL,
    [OperatorId] uniqueidentifier NOT NULL,
    [Status] int NOT NULL,
    CONSTRAINT [PK_Incident] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [IncidentAddress] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] nvarchar(max) NULL,
    [ChineseName] nvarchar(max) NULL,
    [EnglishName] nvarchar(max) NULL,
    CONSTRAINT [PK_IncidentAddress] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [LoginOperator] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [OperatorId] uniqueidentifier NOT NULL,
    [OperatorName] nvarchar(max) NULL,
    CONSTRAINT [PK_LoginOperator] PRIMARY KEY ([ID])
);

GO

CREATE TABLE [ResMonitor] (
    [ID] bigint NOT NULL IDENTITY,
    [RequestID] uniqueidentifier NOT NULL,
    [Version] bigint NOT NULL,
    [CreationDT] datetime2 NOT NULL,
    [CreationBy] bigint NULL,
    [UpdateDT] datetime2 NOT NULL,
    [UpdateBy] bigint NULL,
    [LastUpdate] datetime2 NOT NULL,
    [DataState] int NOT NULL,
    [IncidentNumber] uniqueidentifier NOT NULL,
    [CreationTime] datetime2 NOT NULL,
    CONSTRAINT [PK_ResMonitor] PRIMARY KEY ([ID])
);

GO

INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20200828062947_test1', N'3.1.5');

GO

